package com.shopyourstyle.item;

import android.content.Context;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MagView extends SurfaceView implements SurfaceHolder.Callback {

	//For maintain the surface 
	private int width , height;
	private float scale = 1.0f;
	private Paint textPaint = new Paint();
	private static final String START_TEXT = "MagView Start";
	private static final String PACKAGE_NAME = "ShopStyle.htc" ;
	
	private Context _context;
	private Drawable pic1;
	public MagView(Context context) {
		super(context);
		_context= context;
		SurfaceHolder holder = getHolder();
		holder.addCallback(this);

		setFocusable(true); // make sure we get key events
		setFocusableInTouchMode(true); // make sure we get touch events
		
	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,	int height) {
		// TODO Auto-generated method stub
		this.width = width;
		this.height = height;
		if (width > height) {
			this.scale = width / 480f;
		} else {
			this.scale = height / 480f;
		}
		textPaint.setTextSize(14 * scale);
		Canvas c = getHolder().lockCanvas();
		if (c != null) {
			textPaint.setColor(Color.WHITE);
			//Log.d("Init", "Please show some pic");
			// clear screen
			c.drawColor(Color.DKGRAY );
			float tWidth = textPaint.measureText(START_TEXT);
			c.drawText(START_TEXT, width / 2 - tWidth / 2, height / 2, textPaint);

			MagItem mtest = new MagItem(_context, "ship", "Line1" , "Line2" , "Line3");
			mtest.drawOnCanvas(c, 300, 300, 255);
			mtest.drawOnCanvas(c, 370, 340, 128);
			
			getHolder().unlockCanvasAndPost(c);
		}
		
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}
	
	

}
